<!DOCTYPE html><html lang="en"><head><title>CreateCreditCard.aspx</title></head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"><meta name="groc-relative-root" content=""><meta name="groc-document-path" content="CreateCreditCard.aspx"><meta name="groc-project-path" content="CreateCreditCard.aspx.cs"><link rel="stylesheet" type="text/css" media="all" href="assets/style.css"><script type="text/javascript" src="assets/behavior.js"></script><body><div id="meta"><div class="file-path">CreateCreditCard.aspx.cs</div></div><div id="document"><div class="segment"><div class="comments "><div class="wrapper"><h1 id="createcreditcard-sample">CreateCreditCard Sample</h1>
<p>Using the &#39;vault&#39; API, you can store a 
Credit Card securely on PayPal. You can
use a saved Credit Card to process
a payment in the future.
The following code demonstrates how 
can save a Credit Card on PayPal using 
the Vault API.
API used: POST /v1/vault/credit-card</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">using</span> PayPal.Api;

namespace PayPal.Sample
{
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">partial</span> <span class="hljs-keyword">class</span> CreateCreditCard : BaseSamplePage
    {
        <span class="hljs-keyword">protected</span> <span class="hljs-keyword">override</span> <span class="hljs-keyword">void</span> <span class="hljs-title">RunSample</span>()
        {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="api-context">Api Context</h3>
<p>Pass in a <code>APIContext</code> object to authenticate 
the call and to send a unique request id 
(that ensures idempotency). The SDK generates
a request id if you do not pass one explicitly. 
See <a href="/Source/Configuration.html">Configuration.cs</a> to know more about APIContext.</p></div></div><div class="code"><div class="wrapper">            <span class="hljs-keyword">var</span> apiContext = Configuration.GetAPIContext();</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>A resource representing a credit card that can be used to fund a payment.</p></div></div><div class="code"><div class="wrapper">            <span class="hljs-keyword">var</span> card = <span class="hljs-keyword">new</span> CreditCard()
            {
                expire_month = <span class="hljs-number">11</span>,
                expire_year = <span class="hljs-number">2018</span>,
                number = <span class="hljs-string">"4877274905927862"</span>,
                type = <span class="hljs-string">"visa"</span>,
                cvv2 = <span class="hljs-string">"874"</span>
            };

            <span class="hljs-preprocessor">#<span class="hljs-keyword">region</span> Track Workflow</span>
            <span class="hljs-comment">//--------------------</span>
            <span class="hljs-keyword">this</span>.flow.AddNewRequest(<span class="hljs-string">"Create credit card"</span>, card);
            <span class="hljs-comment">//--------------------</span>
            <span class="hljs-preprocessor">#<span class="hljs-keyword">endregion</span></span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Creates the credit card as a resource in the PayPal vault. The response contains an &#39;id&#39; that you can use to refer to it in the future payments.</p></div></div><div class="code"><div class="wrapper">            <span class="hljs-keyword">var</span> createdCard = card.Create(apiContext);

            <span class="hljs-preprocessor">#<span class="hljs-keyword">region</span> Track Workflow</span>
            <span class="hljs-comment">//--------------------</span>
            <span class="hljs-keyword">this</span>.flow.RecordResponse(createdCard);
            <span class="hljs-comment">//--------------------</span>
            <span class="hljs-preprocessor">#<span class="hljs-keyword">endregion</span></span>
        }
    }
}</div></div></div></div></body></html>